package edu.washington.tcss360.burningpenguins.BPGUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

/**
 * Enables factory-style production of buttons in order to reduce complexity
 * of GUI classes.  All buttons are of same size.  Listeners will need to be
 * attached from a point at which the button action and the user role are
 * both known.
 * This can be accomplished here with appropriate parameters to the attachment
 * method.
 * 
 * Version notes: 	1.1 adjusted colors and size to more aesthetic and neutral values.
 * 
 * @author Sean
 * @version 1.1
 * @since 11/19/2013
 */
public class BPButton extends JButton {

	/**
	 * Enables serializing.
	 */
	private static final long serialVersionUID = -8282312466773482978L;
	
	/**
	 * Generates a button with specifications tailored to the burning penguins GUI.
	 * 
	 * @param name the button label.
	 */
	protected BPButton(String name) {
		super(name);
		this.setBackground(Color.GRAY.brighter());
		this.setMinimumSize(new Dimension(180, 30));
		this.setPreferredSize(new Dimension(180, 30));
		this.setMaximumSize(new Dimension(180, 30));
	}
	
	/**
	 * Defines actions/listeners for BPButtons.
	 * 
	 * @param i the type of button.
	 */
	protected void BPactionFactory(final int i, final BPFrame frame) {
		final BPButton button = this;
		switch (i) {
		case BPActions.LOGIN:
			button.addActionListener(new BPActionListener(frame) {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					Color prior = button.getBackground();
					button.setBackground(Color.GREEN);
					this.setChanged();
					notifyObservers("login");
					button.setBackground(prior);					
				} 
				
			});
			
		}
	}

}
